package com.nrgedge.magnolia.form.validators;

import info.magnolia.context.MgnlContext;
import info.magnolia.module.ModuleRegistry;
import info.magnolia.module.form.validators.Validator;

import javax.servlet.http.HttpServletRequest;

import com.nrgedge.magnolia.ReCaptchaModule;

public class ReCaptchaValidator extends Validator {

    @SuppressWarnings("deprecation")
	@Override
    public boolean validate(String password) {
		final ReCaptchaModule module = (ReCaptchaModule) ModuleRegistry.Factory.getInstance().getModuleInstance("recaptcha");
		final HttpServletRequest request = MgnlContext.getWebContext().getRequest();
		
		if (module.isFieldValidation()) {
			return module.validateRequest(request);
		} else {
			return true;
		}
    }
	
}
